package com.wkbb.basic.service.impl;

import com.wkbb.basic.mapper.NationalityMapper;
import com.wkbb.basic.model.Nationality;
import com.wkbb.basic.service.NationalityService;
import com.wkbb.common.base.BaseServiceImpl;
import com.wkbb.common.constants.RedisKeyConstant;
import com.wkbb.common.dto.basic.DistrictDto;
import com.wkbb.common.dto.basic.NationalityDto;
import com.wkbb.common.redis.RedisTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luowenyan
 * @version V1.0
 * @className NationalityServiceImpl
 * @description
 * @date 2019/7/29 10:52
 */
@Service
@Slf4j
public class NationalityServiceImpl  extends BaseServiceImpl<Nationality> implements NationalityService {
    @Autowired
    private NationalityMapper nationalityMapper;

    @Autowired
    private RedisTemplateUtil redisTemplateUtil;

    @Override
    public List<NationalityDto> getNationalityList() {
        //先从redis中查询,查询不到,再从数据库中查询
        List<NationalityDto> redisNationalityList = (List<NationalityDto>) redisTemplateUtil.get(RedisKeyConstant.WKBB_BASIC_DICT+"nationality:");
        if(null!=redisNationalityList){
            return redisNationalityList;
        }
        List<NationalityDto> nationalityList = nationalityMapper.getNationalityList();
        redisTemplateUtil.set(RedisKeyConstant.WKBB_BASIC_DICT+"nationality:",nationalityList,RedisKeyConstant.EXPIRATION_TIME_1_MONTH);
        return nationalityList;
    }
}
